package cn.rcth.base.util;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: yanghuanyu
 * @Date: 2019/5/25 17:14
 * @Version 1.0
 */
public class ExpressUtils {

    public static String getWuliu(String com,String num){
        String host = "https://wuliu.market.alicloudapi.com";
        String path = "/kdi";
        String method = "GET";
        String appcode = "9db2920b77a14e18ae986e85a89fbfb9";  // !!!替换填写自己的AppCode 在买家中心查看
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("Authorization", "APPCODE " + appcode); //格式为:Authorization:APPCODE 83359fd73fe11248385f570e3c139xxx
        Map<String, String> querys = new HashMap<String, String>();
        querys.put("no", num);// !!! 请求参数
        querys.put("type", com);// !!! 请求参数

        try {
            HttpResponse response = cn.rcth.business.util.HttpUtils.doGet(host, path, method, headers, querys);
            System.out.println(response.toString());//如不输出json, 请打开这行代码，打印调试头部状态码。
            //状态码: 200 正常；400 URL无效；401 appCode错误； 403 次数用完； 500 API网管错误
            //获取response的body
            System.out.println(response.getEntity());
            HttpEntity entity = response.getEntity();
            return EntityUtils.toString(response.getEntity()); //输出json
        } catch (Exception e) {
            e.printStackTrace();
            return "查询失败";
        }

    }
}
